<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>单图组</span>
    </div>
    <div class="bds">
      <el-collapse v-model="activeNames">
        <el-collapse-item title="组件内容" name="1">
          <draggable element="ul" v-model="data.imglist" :animation='200'>
            <div class="item" v-for="(item,i) in data.imglist" :key='i'>
              <i class="icon-abl-close el-icon-error" @click="removePic(i)"></i>
              <div class="dragbox"><i class="el-icon-d-caret"></i></div>
              <div class="img_box">
                <Upload :tempUrl="item.url"  @input="getimg($event,i)"></Upload>
              </div>
              <div class="item_select">
            <!--    <div class="select_link" style="margin-bottom:8px;">
                  <div class="select_btn" @click="chooseLink">
                    <i class="el-icon-link"></i>&nbsp;<span>选择链接</span>
                  </div>
                </div> -->
                 <div @click="selectlink(item, i)"><Linkdiv :linkdata="item.linkdata"></Linkdiv></div>
                <!-- <Linkdiv :linkdata="item"></Linkdiv> -->
                <span class="tip">建议图片宽度750px，高度跟随第一张图片的高度变化</span>
              </div>
            </div>
          </draggable>
          <el-button @click="addimg">添加</el-button>
        </el-collapse-item>

        <el-collapse-item title="组件样式" name="2">
          <el-form size="medium" label-width="100px">
            <el-form-item label="上间距">
              <div class="slider_box">
                <el-slider class="slider_item" :max="20" v-model="data.margin.top"></el-slider>
                <el-input-number v-model="data.margin.top" :controls='false' :min="0" :max="20"></el-input-number>
              </div>
            </el-form-item>

            <el-form-item label="下间距">
              <div class="slider_box">
                <el-slider class="slider_item" :max="20" v-model="data.margin.bottom"></el-slider>
                <el-input-number v-model="data.margin.bottom" :controls='false' :min="0" :max="20"></el-input-number>
              </div>
            </el-form-item>

            <el-form-item label="左右间距">
              <div class="slider_box">
                <el-slider class="slider_item" :max="20" v-model="data.margin.lr"></el-slider>
                <el-input-number v-model="data.margin.lr" :controls='false' :min="0" :max="20"></el-input-number>
              </div>
            </el-form-item>

            <el-form-item label="图片间距">
              <div class="slider_box">
                <el-slider class="slider_item" :max="20" v-model="data.margin.pic"></el-slider>
                <el-input-number v-model="data.margin.pic" :controls='false' :min="0" :max="20"></el-input-number>
              </div>
            </el-form-item>

            <el-form-item label="圆角">
              <div class="slider_box">
                <el-slider class="slider_item" :max="20" v-model="data.radius"></el-slider>
                <el-input-number v-model="data.radius" :controls='false' :min="0" :max="20"></el-input-number>
              </div>
            </el-form-item>

          </el-form>
        </el-collapse-item>
      </el-collapse>
    </div>
  </el-card>
</template>

<script>
import Upload from '@/components/Upload/SingleImage2';
import draggable from 'vuedraggable';
import Linkdiv from '@/components/Link/index';

export default {
  data(){
    return{

      activeNames: ['1', '2']
    }
  },
  props: {
    data:{
      type:Object,
      default:{}
    }
  },
  components: {
    Upload,
    draggable,
    Linkdiv
  },
  methods: {
    //删除图片
    removePic(index){
      this.data.imglist.splice(index,1);
    },
    selectlink(item, i) {
      this.acivedata = item;
      this.activid = i;
      this.$parent.showlinkselcet(item);
    },
    getAData(item) {
     this.acivedata.linkdata = item;
    },

    //获取图片
    getimg(data,i) {
      this.data.imglist[i].url = data;
    },
    //添加图片
    addimg() {
      this.data.imglist.push({
        url: '',
        linkdata: {
          link: '',
          name: '',
          id: '',
          type: '',
          login_type: 1,
        },
      })
    }
  }
}
</script>

<style lang="scss" scoped>
//样式覆盖
.bds{
  .el-collapse-item__wrap{
    overflow: visible;
  }
}

.item {
  position: relative;
  width: 100%;
  display: flex;
  cursor: pointer;
  background: #F4F6F8;
  border-radius: 2px;
  box-sizing: border-box;
  border: 1px solid #E9EDEF;
  margin-bottom: 10px;
  padding: 10px 10px;

  &:hover{
    .icon-abl-close{
      display: block;
    }
  }

  .icon-abl-close{
    position: absolute;
    top: -6px;
    right: -9px;
    color: rgba(0, 0, 0, 0.3);
    display: none;
    font-size: 16px;
  }

  .dragbox{
    color: #909399;
    line-height: 60px;
    font-size: 16px;
    margin-right: 10px;
  }

  .img_box {
    width: 60px;
    height: 60px;
  }

  .item_select {
    flex: 1;
    margin-left: 10px;

    .select_link {
      background: #fff;

      .select_btn {
        padding: 4px 6px;
        color: #2D8CF0;
        box-sizing: border-box;
        border: 1px solid #fff;

        &:hover{
          border: 1px solid #2D8CF0;
        }
      }
    }

    .tip {
      display: block;
      font-family: PingFang SC;
      font-style: normal;
      font-weight: normal;
      font-size: 12px;
      line-height: 18px;
      color: #939799;
      /* margin-top: 8px; */
    }
  }
}
</style>
